package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.SkillReplaceCfg;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 【普通攻击】变成【刺豚】，造成120%伤害，受到攻击必定以此反击
 */
public class 憋气反击PH extends PassiveHandler {

	private int 刺豚技能;

	private int 反击概率;

	//刺豚技能=？？&反击概率=10000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		刺豚技能 = args.getInt("刺豚技能", 0);
		反击概率 = args.getInt("反击概率", 0);
	}

	@Override
	public void onFirstEnter(ActionCtx action) {
		SkillReplaceCfg cfg = new SkillReplaceCfg();
		cfg.type = GDSkill.Type.ATTACK;
		cfg.replaceSkill = 刺豚技能;
		skill.owner.skill.addReplace(action.getCfg(),cfg);
	}

	private boolean needStrike;

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (needStrike) {
			return;
		}
		if (action.getMove().isAppend()) {
			return;
		}
		if (!XT.chance(反击概率)) {
			return;
		}
		needStrike = true;
	}

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (needStrike) {
			Skill appendSkill = skill.owner.skill.getAttack();
			if (appendSkill != null) {
				appendSkill.param.addAppointTarget(move.getActor());
				AppendMove append = new AppendMove(skill.owner, appendSkill);
				move.getTurn().addAppend(append);
			}
			needStrike = false;
		}
	}
}
